<?php
    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
?>
<div class="st-cp-pg-blog"> 
    
    <h1 class="st_tl">Blog da Piti</h1>
    
    <div class="cnt_lst_bg">
    <?php foreach($this->blog as $blog){ 
        $img = glob('public/upload/blog/'.$blog['BLO_ID'].'_tb.*');
        
	// erro de troca de nome controller
	if($blog['BLO_ID'] < 21)  $url = $_SERVER['HTTP_HOST'].''.$this->urlbase.'/blog/index/id/'.$blog['BLO_ID'];
	else $url = $_SERVER['HTTP_HOST'].''.$this->urlbase.'/blogdapiti/index/id/'.$blog['BLO_ID'];        

	$pos = strpos($url, 'www.');
        if ($pos === false) $url = 'http://www.'.$url;
        else $url = 'http://'.$url;
            
    ?>
        <div id="post_<?php echo $blog['BLO_ID']?>" class="cnt_it_bg">
            
            <div class="cnt_data">
                <div class="data">
                    <div class="dia"><?php echo substr($blog['BLO_DAT'], 8,2); ?></div>
                    <div class="mes"><?php echo strtoupper(Datetools::num_Mes(substr($blog['BLO_DAT'], 5,2))); ?><br></div>
                    <div class="ano"><?php echo substr($blog['BLO_DAT'],0,4); ?></div>
                </div>
                <img src="<?php echo $this->urlbase.'/'.$img[0]; ?>" class="foto" alt="<?php echo $blog['BLO_NOM']; ?>" />
            </div>

                       
            <div class="txt_bg">
                <div class="tl"><?php echo $blog['BLO_NOM']; ?></div>
                <div class="tl_dt">
                    <?php echo Datetools::semana(Datetools::diasemanaData($blog['BLO_DAT'])); ?>, Postado às <?php echo Datetools::hora_hm($blog['BLO_HOR']); ?>
                </div>
                <div class="txt"><?php echo $blog['BLO_TXT']; ?></div>

                <div id="fb-root"></div>
                <script>(function(d, s, id) {
                  var js, fjs = d.getElementsByTagName(s)[0];
                  if (d.getElementById(id)) return;
                  js = d.createElement(s); js.id = id;
                  js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&appId=688243397900389&version=v2.0";
                  fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));</script>
                
                <iframe src="//www.facebook.com/plugins/like.php?href=<?php echo urlencode($url); ?>&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=false&amp;share=true&amp;height=35&amp;appId=688243397900389" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:35px;" allowTransparency="true"></iframe>
                
                <div class="fb-comments" data-href="<?php echo $url; ?>" data-width="575" data-numposts="5" data-colorscheme="light"></div>
                
            </div>
        </div>
    <?php } ?>
        <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
    </div>
     
    <div class="bar_lt">
            
        <div class="st_login">
            <div class="tl">Área do Aluno</div>
            <form id="formlogin" method="post" action="<?php echo $this->urlbase.'/ead/auth/login'; ?>">
                <input type="text" id="f_usuario" name="usuario" placeholder="usuário">
                <input type="password" id="f_senha" name="senha" placeholder="senha">
                <a href="<?php echo $this->urlbase.'/esqueciminhasenha'; ?>" class="esq_senha">esqueci minha senha</a> <input type="submit" name="entrar" value="entrar" />
            </form>    
        </div>

        <h2 class="st_tl">Categorias</h2>
        <ul class="categoria">
        <?php 
        $obj = $db->fetchAll('SELECT SQL_CACHE * FROM CATEGORIA_BLOG WHERE CTB_STA = 1 ORDER BY CTB_NOM ASC');
        foreach($obj as $o){
            $bol = $db->fetchRow('SELECT SQL_CACHE BLO_ID FROM BLOG WHERE CTB_ID = '.$o['CTB_ID'].' and BLO_STA = 1');
            if($bol['BLO_ID'] > 0){
        ?>
            <li><span>&rsaquo;</span> <a href="<?php echo $this->urlbase.'/blogdapiti/index/cat/'.$o['CTB_ID']; ?>"><?php echo $o['CTB_NOM'] ?></a></li>
        <?php 
            } 
        }?>
        </ul>

        <h2 class="st_tl">Tags</h2>

        <?php 
        $html = '';
        $obj = $db->fetchAll('SELECT SQL_CACHE DISTINCT BLO_TAG FROM BLOG WHERE BLO_STA = 1 ORDER BY BLO_TAG ASC');
        foreach($obj as $o){
            $html .= '<a href="'.$this->urlbase.'/blogdapiti/index/tag/'.$o['BLO_TAG'].'">'.$o['BLO_TAG'].'</a>, ';
        }
        if($html > '') $html = substr($html,0,-2);
        ?>
        <p class="tag"><?php echo $html; ?></p>

        <iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fpiti.redacao&amp;width&amp;height=290&amp;colorscheme=light&amp;show_faces=true&amp;header=true&amp;stream=false&amp;show_border=true&amp;appId=688243397900389" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:290px; width: 270px;" allowTransparency="true"></iframe>
    </div>
</div>
<?php if($this->id > 0){?>
<script>
$(document).ready(function (){
    setTimeout( function(){
        $('html, body').animate({
            scrollTop: $("#post_<?php echo $this->id; ?>").offset().top
        }, 1500); } , 1000) ;
    
});
</script>
<?php } ?>
